try {
  const defaultSettings = require('@/settings.js')
  const xhr = new XMLHttpRequest()
  const configurls = process.env.NODE_ENV === 'development' ? defaultSettings.developmentApi + '/api/config' : '/api/config'
  xhr.open('get', configurls, false)
  xhr.onload = (e) => {
    if (e.currentTarget.status !== 200) return
    const configdata = JSON.parse(e.currentTarget.response)
    if (configdata.code === 0) {
      defaultSettings.project_config = configdata.data
    }
  }
  xhr.send()
} catch {
  // console.log('分学校控制菜单请求失败')
}

import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

/* Layout */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

